<template>
  <a-card :bordered="false">

    <div class="img-view" v-if="showImg">
      <!-- 遮罩层 -->
      <div class="img-layer" v-if="showImg" @click="viewImg"></div>

      <div  v-show="jianShow">
        <img :src="leftjian" class="left" @click="handleClickLeft"/>
      </div>

      <div class="img" v-if="showImg" @click="viewImg" >
        <img :src="imgSrc[imgIndex]">
      </div>

      <div v-show="jianShow">
        <img :src="jiantou" class="right" @click="handleClickRight"/>
      </div>

    </div>

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <!--<a-col :xl="6" :lg="7" :md="8" :sm="24">-->
            <!--<a-form-item label="执行人">-->
              <!--<a-input placeholder="请输入执行人" v-model="queryParam.createName"></a-input>-->
            <!--</a-form-item>-->
          <!--</a-col>-->

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="活动名称">
              <a-input placeholder="请输入活动名称" v-model="queryParam.actName"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="门店名称">
              <a-input placeholder="请输入门店名称" v-model="queryParam.terminalName"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="downExportXls('tpmActExecDetail_report')">导出</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
        selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <template slot="imgUrl" slot-scope="text, record, index">
          <div class="anty-img-wrap">
            <a-avatar shape="square" :src="record.imgUrl[0]" @click="clickImg(record.imgUrl)"/>
          </div>
        </template>

        <span slot="action" slot-scope="text, record">
        <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
        </a-popconfirm>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <!--<TpmActExecModal ref="modalForm" @ok="modalFormOk"></TpmActExecModal>-->
  </a-card>
</template>

<script>
  import '@/assets/less/TableExpand.less'
  import TpmActExecModal from './modules/TpmActExecModal'
  import {PageListMixin} from '@/mixins/PageListMixin'
  import {getAction} from '@/api/manage'
  import JDate from '@comp/cn-form/JDate'

  export default {
    name: "TpmActExecList",
    mixins: [PageListMixin],
    components: {
      TpmActExecModal,
      JDate
    },
    data() {
      return {
        jianShow: '',
        leftjian: require('@/assets/leftjian.png'),
        jiantou: require('@/assets/jiantou.png'),
        message: '',
        imgIndex:0,
        showImg: false,
        imgSrc: [],
        description: '活动执行页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '图片',
            align: "center",
            dataIndex: 'imgUrl',
            scopedSlots: {customRender: "imgUrl"}
          },
          {
            title: '活动编码',
            align: "center",
            dataIndex: 'actCode'
          },
          {
            title: '活动标题',
            align: "center",
            dataIndex: 'actName'
          },
          {
            title: '门店编码',
            align: "center",
            dataIndex: 'terminalCode'
          },
          {
            title: '门店名称',
            align: "center",
            dataIndex: 'terminalName'
          },
          {
            title: '上级客户',
            align: "center",
            dataIndex: 'custName'
          },
          {
            title: '城市',
            align: "center",
            dataIndex: 'cityOrgName'
          },
          {
            title: '省区',
            align: "center",
            dataIndex: 'provinceOrgName'
          },
          {
            title: '大区',
            align: "center",
            dataIndex: 'dqOrgName'
          },
          {
            title: '执行描述',
            align: "center",
            dataIndex: 'execRemarks'
          },
          {
            title: '执行人岗位',
            align: "center",
            dataIndex: 'positionName'
          },
          {
            title: '执行人',
            align: "center",
            dataIndex: 'createName'
          },
          {
            title: '执行时间',
            align: "center",
            dataIndex: 'execTime'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: "center",
            scopedSlots: {customRender: 'action'}
          }
        ],
        url: {
          list: window._CONFIG['domianTpmURL'] + "/collection/CollectionSfaInfoPC/findPageListPC",
          delete: window._CONFIG['domianTpmURL'] + "/collection/CollectionSfaInfoPC/delete",
          deleteBatch: window._CONFIG['domianTpmURL'] + "/collection/CollectionSfaInfoPC/deleteBatch",
          // exportXlsUrl: window._CONFIG['domianTpmURL'] + "budget/tpmBudgetYear/exportXls",
          // importExcelUrl: window._CONFIG['domianTpmURL'] + "budget/tpmBudgetYear/importExcel",
          // startOrStopUrl: window._CONFIG['domianTpmURL'] + "budget/tpmBudgetYear/startOrStop",
        },
      }
    },
    computed: {
      // importExcelUrl: function () {
      //   return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      // },
    },
    methods: {

      clickImg(path) {
        this.imgIndex = 0;
        //console.log(path);
        this.showImg = true;
        // 获取当前图片地址
        this.imgSrc = path;
        //console.log(this.imgSrc)
        this.jianShow = false;
        if (path.length>1){
          this.jianShow = true;
          // console.log(this.jianShow);
        }
      },
      viewImg() {
        this.showImg = false;
      },
      handleClickLeft(){
        if(this.imgIndex===0){
          this.imgIndex=(this.imgSrc.length)-1;
          return
        }
        if(this.imgIndex<this.imgSrc.length && this.imgIndex!==0){
          this.imgIndex--;
          return
        }
      },
      handleClickRight(){
        if(this.imgIndex<(this.imgSrc.length-1)){
          this.imgIndex++;
          return
        }
        if(this.imgIndex===(this.imgSrc.length-1)){
          this.imgIndex=0;
          return
        }
      },
      // startorstop: function (status) {
      //   if (!this.url.startOrStopUrl) {
      //     this.$message.error("请设置url启用停用!")
      //     return
      //   }
      //   if (this.selectedRowKeys.length != 1) {
      //     this.$message.warning('请选择一条记录！');
      //     return;
      //   } else {
      //     var id = this.selectedRowKeys[0];
      //     var that = this;
      //     that.loading = true;
      //     getAction(this.url.startOrStopUrl, {id: id, status: status}).then((res) => {
      //       if (res.success) {
      //         that.$message.success(res.message);
      //         that.loadData();
      //       } else {
      //         that.$message.warning(res.message);
      //       }
      //       that.loading = false;
      //     });
      //   }
      // }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
  /*动画*/
  .fade-enter-active,
  .fade-leave-active {
    transition: all .2s linear;
    transform: translate3D(0, 0, 0);
  }

  .fade-enter,
  .fade-leave-active {
    transform: translate3D(100%, 0, 0);
  }

  /* bigimg */

  .img-view {
    position: relative;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  /*遮罩层样式*/
  .img-view .img-layer {
    position: fixed;
    z-index: 99998;
    top: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.7);
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  /*不限制图片大小，实现居中*/
  .img-view .img img {
    position: absolute;
    min-width: 50%;
    max-width: 50%;
    display: block;
    left: 0;
    right: 0;
    margin: auto;
    z-index: 99999;
  }
  .left {
    position: absolute;
    min-width: 20%;
    max-width: 20%;
    display: block;
    left: 0px;
    margin: auto;
    z-index: 99999;
    top: 50%;
  }
  .right {
    position: absolute;
    min-width: 20%;
    max-width: 20%;
    display: block;
    right: 0px;top: 50%;
    margin: auto;
    z-index: 99999;
  }
</style>